// Help
// 
// 保佑没Bug 
//
// Created by AS on 2019/4/10. 
//
// Copyright © 2018 AS. All rights reserved.
// 

#import "LhView.h"
@interface LhView()
/**  */
@property (nonatomic,strong) UILabel *label;
/**  */
@property (nonatomic,strong) NSMutableArray *bars;
/**  */
@property (nonatomic,strong) NSMutableArray *labels;
/**  */
@property (nonatomic,strong) UILabel *addLabel;
@end
@implementation LhView

-(NSMutableArray *)bars{
    if (!_bars) {
        _bars = [NSMutableArray array];
    }
    return _bars;
}

-(NSMutableArray *)labels{
    if (!_labels) {
        _labels = [NSMutableArray array];
    }
    return _labels;
}


- (instancetype)init{
    self = [super init];
    if (self) {
        [self initSubView];
    }
    return self;
}

-(void)initSubView{
    
    for (int i=0;i<7;i++) {
        UIImageView *imageView = [UIImageView new];
        imageView.contentMode = UIViewContentModeScaleToFill;
        [self addSubview:imageView];
        [self.bars addObject:imageView];
        
        UILabel *label = [UILabel new];
        label.font = Font12;
        label.textColor = HexRGB(0x222222);
        label.textAlignment = NSTextAlignmentCenter;
        [self addSubview:label];
        [self.labels addObject:label];
        
        self.addLabel = [UILabel new];
        self.addLabel.text = @"+";
        self.addLabel.font = Font16;
        self.addLabel.textColor = HexRGB(0x222222);
        self.addLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.addLabel];
        
    }
}

-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat margin = ZoomHeight(5);
    CGFloat width = 24;//(self.width - (9 * margin)) / 10;
    for (int i=0;i<self.bars.count;i++) {
        
        CGFloat x = i * margin + (i * width);
        
        if (i == 6) {
            self.addLabel.frame = CGRectMake(x,0, width / 2, self.height);
            x = (i + 1) * margin + ((i + 1) * width) - width / 2;
        }
        
        UIImageView *imageView = self.bars[i];
        imageView.frame = CGRectMake(x,0, width, width);
        
        UILabel *label = self.labels[i];
        label.frame = CGRectMake(x,CGRectGetMaxY(imageView.frame) + 3, imageView.width, 15);
    }
}

-(void)setModel:(MModel *)model{
    _model = model;

    NSString *path = [PathDocument stringByAppendingPathComponent:@"ionic/www/assets/gameIcon"];

    for (int i=0; i<model.openNumbers.count; i++) {
        UIImageView *imageView = self.bars[i];
        NSString *imageName = @"";
        imageName = [NSString stringWithFormat:@"lh%@.png",model.openNumbers[i]];
        NSString *imagePath = [NSString stringWithFormat:@"%@/%@", path,imageName];
        UIImage *image = [[UIImage alloc]initWithContentsOfFile:imagePath];
        if (!image) {
            NSLog(@"%@",imageName);
        }
        imageView.image = image;
        
        UILabel *label = self.labels[i];
        label.text = [self text:model.openNumbers[i]];
        
    }
    
}

-(NSString *)text:(NSString *)value{
    
    if ([value isEqualToString:@"01"] || [value isEqualToString:@"13"] || [value isEqualToString:@"25"] || [value isEqualToString:@"37"] || [value isEqualToString:@"49"] ) {
        return @"猪";
    }else if ([value isEqualToString:@"02"] || [value isEqualToString:@"14"] || [value isEqualToString:@"26"] || [value isEqualToString:@"38"]){
        return @"狗";
    }else if ([value isEqualToString:@"03"] || [value isEqualToString:@"15"] || [value isEqualToString:@"27"] || [value isEqualToString:@"39"]){
        return @"鸡";
    }else if ([value isEqualToString:@"04"] || [value isEqualToString:@"16"] || [value isEqualToString:@"28"] || [value isEqualToString:@"40"]){
        return @"猴";
    }else if ([value isEqualToString:@"05"] || [value isEqualToString:@"17"] || [value isEqualToString:@"29"] || [value isEqualToString:@"41"]){
        return @"羊";
    }else if ([value isEqualToString:@"06"] || [value isEqualToString:@"18"] || [value isEqualToString:@"30"] || [value isEqualToString:@"42"]){
        return @"马";
    }else if ([value isEqualToString:@"07"] || [value isEqualToString:@"19"] || [value isEqualToString:@"31"] || [value isEqualToString:@"43"]){
        return @"蛇";
    }else if ([value isEqualToString:@"08"] || [value isEqualToString:@"20"] || [value isEqualToString:@"32"] || [value isEqualToString:@"44"]){
        return @"龙";
    }else if ([value isEqualToString:@"09"] || [value isEqualToString:@"21"] || [value isEqualToString:@"33"] || [value isEqualToString:@"45"]){
        return @"兔";
    }else if ([value isEqualToString:@"10"] || [value isEqualToString:@"22"] || [value isEqualToString:@"34"] || [value isEqualToString:@"46"]){
        return @"虎";
    }else if ([value isEqualToString:@"11"] || [value isEqualToString:@"23"] || [value isEqualToString:@"35"] || [value isEqualToString:@"47"]){
        return @"牛";
    }else if ([value isEqualToString:@"12"] || [value isEqualToString:@"24"] || [value isEqualToString:@"36"] || [value isEqualToString:@"48"]){
        return @"鼠";
    }
    return @"";
    
}



@end

